﻿using System;
using System.Data;
using System.Collections.Generic;
using Chenxin.Lib.Business.Entity;
namespace Chenxin.Lib.Business.BLL
{
    /// <summary>
    /// 业务逻辑类t_Preliminary_SubInfo2 的摘要说明。
    /// </summary>
    public class PreSalerInfo
    {
        public PreSalerInfo()
        { }
        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2 model)
        {
            Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2 model)
        {
            Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(Guid RecordId)
        {

            Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.Delete(RecordId);
        }

        /// <summary>
        /// 根据报备ID删除关联数据
        /// </summary>
        public void DeleteByMainId(Guid MainId)
        {

            Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.DeleteByMainId(MainId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2 GetModel(Guid RecordId)
        {

            return Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.GetModel(RecordId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2> GetModelList(string strWhere)
        {
            DataSet ds = Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 根据MainId获取买方列表信息
        /// </summary>
        /// <param name="MainId">关联ID</param>
        /// <returns></returns>
        public List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2> GetModelListByMainId(string MainId)
        {
            string strSql = string.Empty;
            strSql = string.Format(" MainId='{0}' ", MainId);
            return GetModelList(strSql);
        }

        /// <summary>
        /// 根据MainId获取买方列表信息
        /// </summary>
        /// <param name="MainId">关联ID</param>
        /// <returns></returns>
        public DataSet GetListByMainId(string MainId)
        {
            string strSql = string.Empty;
            strSql = string.Format(" MainId='{0}' ", MainId);
            DataSet ds = Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.GetList(strSql);
            return ds;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2> DataTableToList(DataTable dt)
        {
            List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2> modelList = new List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2 model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2();
					if(dt.Rows[n]["RecordId"].ToString()!="")
					{
						model.RecordId=new Guid(dt.Rows[n]["RecordId"].ToString());
					}
					if(dt.Rows[n]["MainId"].ToString()!="")
					{
						model.MainId=new Guid(dt.Rows[n]["MainId"].ToString());
					}
					model.SaleNamePublic=dt.Rows[n]["SaleNamePublic"].ToString();
					model.SaleIDCardPublic=dt.Rows[n]["SaleIDCardPublic"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 根据房源ID获取最新下家信息
        /// </summary>
        /// <param name="HouseId"></param>
        /// <returns></returns>
        public List<Chenxin.Lib.Business.Entity.t_Preliminary_SubInfo2> GetLatestListByHouseId(string HouseId)
        {
            return Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.GetLatestListByHouseId(HouseId);
        }

        #endregion  成员方法
    }
}

